using System;
using System.Collections.Generic;
using System.Text;

using System.Collections;

using Chat.metier;
using Chat.dao;

using Spring.Context;
using Spring.Context.Support;
using log4net;
using ChatServer;

namespace Chat.service
{
    class MessageService
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(MessageService));
        /// <summary>
        /// Cette methode renvoit un utiisateur a partir de son id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Message getById(int id)
        {
            Message message = null;
            try
            {
                IMessageDAO m = (IMessageDAO)InitFramework.springCtx.GetObject("message.dao");
                message = m.getById(id);
            }
            catch (Exception e1)
            {
                log.Warn("Errreur dans Message_getById", e1);
                return null;
            }
            return message;
        }

        /// <summary>
        /// Cette methode renvoit tous les utilisateurs
        /// </summary>
        /// <returns></returns>
        public IList getAll()
        {
            IList list = null;
            try
            {
                IMessageDAO m = (IMessageDAO)InitFramework.springCtx.GetObject("message.dao");
                list = m.getAll();
            }
            catch (Exception e1)
            {
                log.Warn("Erreur dans Message_getAll", e1);
                return null;
            }
            return list;
        }

        /// <summary>
        /// Save a message for a User to his Contact
        /// </summary>
        /// <param name="IdUser"></param>
        /// <param name="IdContact"></param>
        /// <param name="Message"></param>
        public void saveMessage(int IdUser, int IdContact, String Message)
        {
            try
            {
                IMessageDAO m = (IMessageDAO)InitFramework.springCtx.GetObject("message.dao");
                m.saveMessage(IdUser, IdContact, Message);
            }
            catch (Exception e1)
            {
                log.Warn("Erreur dans Message_saveMessage", e1);
            }
        }

    }
}
